using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Configuration;
using System.Timers;

using ImageMonitor;

namespace TPDSTestHarness
{
    public partial class MainForm : Form
    {
        ImageMonitorClass monitor = new ImageMonitorClass( );
        TPDSConfig.TPDSConfig configFile = null;

        System.Timers.Timer timer = null;

        public MainForm( )
        {
            InitializeComponent();
        }

        /// <summary>
        /// Performs initiallisation code similar to service start. Must be run on application start before any further tests are done.
        /// </summary>
        private void processInitialise_Click( object sender, EventArgs e )
        {
            configFile = monitor.ProcessStart( );
        }

        /// <summary>
        /// Simulate the service reacting to changed *.set files. Will process all set files that exist.
        /// </summary>
        private void processSet_Click( object sender, EventArgs e )
        {
            // Must have run the initialisation code first.
            if( configFile == null )
                return;

            // Look for all *.set files within the web site's image root folder.
            DirectoryInfo drInfo = new DirectoryInfo( Path.Combine( ConfigurationManager.AppSettings[ "WebServerPath" ], configFile.ImageMonitorRootFolder ) );
            FileInfo[ ] files = drInfo.GetFiles( "*.set", SearchOption.AllDirectories );

            // Process each file.
            foreach( FileInfo file in files )
                monitor.ProcessImageSet( file.FullName );
        }

        /// <summary>
        /// Simulate the service timer looking for waiting sets.
        /// </summary>
        private void waitingset_Click( object sender, EventArgs e )
        {
            // Must have run the initialisation code first.
            if( configFile == null )
                return;

            // All monitor function
            monitor.ProcessWaitingImageSets( );
        }
   }
}